package com.wn.controller;

import com.wn.annotation.RequireRoles;
import com.wn.entity.Catering;
import com.wn.entity.Scenic;
import com.wn.service.ScenicService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * (Scenic)表控制层
 *
 * @author makejava
 * @since 2020-10-26 09:40:56
 */
@RestController
@RequestMapping("scenic")
public class ScenicController {
    /**
     * 服务对象
     */
    @Resource
    private ScenicService scenicService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Scenic selectOne(String id) {
        return this.scenicService.queryById(id);
    }

    /**
     * 动态查询
     * @param scenicPageParam
     * @return
     */
    @SystemControllerLog(description = "分页查询景点信息")
    @PostMapping("/searchSomeScenicByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Scenic> scenicPageParam,
                                @RequestHeader("token") String token){

        return Rsp.success(scenicService.searchSomeByPage(scenicPageParam));
    }

    @SystemControllerLog(description = "动态修改景点信息")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/updateScenic")
    @ApiOperation("动态修改")
    public Rsp updateCatering(@RequestBody @Valid Scenic scenic, @RequestHeader("token") String token){
        System.out.println(scenic);

        //scenic.setUpdatauserid("1");
        return scenicService.update(scenic) == 1?Rsp.success(null).msg("修改成功"):Rsp.fail().msg("修改失败");
    }

    @SystemControllerLog(description = "通过ID逻辑删除景点信息")
    @RequireRoles(roles = {"super_admin"},index = 1)
    @PostMapping("/deleteScenicLogical")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteCateringLogical(@RequestBody Scenic scenic,@RequestHeader("token") String token){

        scenic.setIsdeleted(1);
        //scenic.setUpdatauserid("1");
        scenic.setUpdatatime(new Date());
        return scenicService.update(scenic) == 1?Rsp.success(null).msg("删除成功"):Rsp.fail().msg("删除失败");
    }

    @SystemControllerLog(description = "添加单个景点信息")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/addOneScenic")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Scenic scenic,@RequestHeader("token") String token){

        //scenic.setCreateuserid("1");
        scenic.setCreatetime(new Date());
        return scenicService.insert(scenic) == 1?Rsp.success(null).msg("添加成功"):Rsp.fail().msg("添加失败");
    }

    @GetMapping("selScenic")
    public List<Scenic> selHotel(Object longitude, Object latitude){
        List<Scenic> scenic = scenicService.selScenic(longitude, latitude);
        return scenic;
    }

}
